package com.briup.jd2407cms.web.controller;

import com.briup.jd2407cms.aop.Logging;
import com.briup.jd2407cms.domain.Article;
import com.briup.jd2407cms.domain.DTO.ArticleParam;
import com.briup.jd2407cms.service.ArticleService;
import com.briup.jd2407cms.util.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @BelongsProject: JD2407-cms
 * @BelongsPackage: com.briup.jd2407cms.web.controller
 * @Author: 鲨鲨天下第一
 * @CreateTime: 2024-11-19  09:05
 * @Description: TODO
 * @Version: 1.0
 */
@Api(tags = "资讯模块")
@RestController
@RequestMapping("/auth/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    @ApiOperation(value = "新增或修改文章", notes = "文章id存在为修改，不存在为新增")
    @Logging("新增或修改文章")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(@RequestBody Article article, HttpServletRequest request){
        return Result.success(articleService.saveOrUpdate(article, request)?"新增或修改成功":"新增或修改失败");
    }

    @ApiOperation(value = "分页+条件查询文章", notes = "")
    @Logging("分页+条件查询文章")
    @PostMapping("/query")
    public Result query(@RequestBody ArticleParam articleParam) {
        return Result.success(articleService.page(articleParam));
    }

    @ApiOperation(value = "通过id查询资讯信息", notes = "用于修改数据时的数据回显")
    @Logging("通过id查询资讯信息")
    @GetMapping("/queryById/{id}")
    public Result queryById(@PathVariable String id) {
        return Result.success(articleService.getById(id));
    }

    @ApiOperation(value = "批量删除资讯信息", notes = "")
    @Logging("批量删除资讯信息")
    @DeleteMapping("/deleteByBatch/{ids}")
    public Result deleteByBatch(@PathVariable List<String> ids) {
        return Result.success(articleService.removeByIds(ids)?"删除成功":"删除失败");
    }

    @ApiOperation(value = "审核资讯信息", notes = "此接口用于审核文章，文章id必须有效，status: 审核通过、审核未通过")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "文章id", required = true, dataType = "String"),
            @ApiImplicitParam(name = "status", value = "审核状态", required = true, dataType = "String")
    })
    @Logging("审核资讯信息")
    @PutMapping("/review")
    public Result  reviewArticle(String id, String status) {
        return Result.success(articleService.reviewArticle(id, status)?"审核成功":"审核失败");
    }

    @ApiOperation(value = "查询所有资讯信息", notes = "用于评论管理条件查询文章的数据回显")
    @Logging("查询所有资讯信息")
    @GetMapping("/getAll")
    public Result getAll() {
        return Result.success(articleService.list());
    }

}
